
/**
 * @author iallai
 * @desc 非java程序员, 无视命名规范
 */

import java.util.Scanner;

public class P1Q1 {
    public static void main(String[] args) {
        Day day = new Day();
        day.getDayByScanner();
    }
}

class Day {
    private boolean _isLeapYear(int year) {
        return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0) ? true : false;
    }

    private int _getMonth(Scanner sc) {
        int m = sc.nextInt();
        if (m > 12 || m < 1) {
            System.out.println("请输入正确的月份:");
            this._getMonth(sc);
        }
        return m;
    }

    private int _getDay(Scanner sc) {
        int d = sc.nextInt();
        // todo 通过年月来验证
        if (d > 31 || d < 1) {
            System.out.println("请输入正确的日:");
            this._getDay(sc);
        }
        return d;
    }

    // 优化 : 可以存到一个数组里面, 这里的isLead也传深了
    private int _getCurrentDayByMonth(int month, boolean isLead) {
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
            case 2:
                return isLead ? 29 : 28;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            default:
                return 0;

        }

    }

    private void _countDay(int year, int month, int day, boolean isLead) {
        int sum = 0;
        for (int i = 1; i < month; i++) {
            sum = sum + this._getCurrentDayByMonth(i, isLead);
            System.out.println(i);
        }
        System.out.println(year + "-" + month + "-" + day);
        System.out.println("经过了");
        System.out.println("total: " + (sum + day));
    }
    // private boolean flag = false;
    // Todo: java如何写构造函数

    public void getDayByScanner() {
        Scanner sc = new Scanner(System.in);
        boolean flag = false;
        while (!flag) {
            System.out.println("请输入年:");
            int y = sc.nextInt();
            boolean isLead = this._isLeapYear(y);

            String message = isLead ? y + "年是润年" : y + "年不是润年";
            System.out.println(message);

            System.out.println("请输入月:");
            int m = this._getMonth(sc);

            System.out.println("请输入日:");
            int d = this._getDay(sc);

            this._countDay(y, m, d, isLead);

            System.out.println("是否继续?输入任意键继续, 输入n退出程序");
            // Todo: 默认值;

            String needRepeat = sc.next();
            if (needRepeat.equals("n") || needRepeat.equals("N")) {
                flag = true;
                message = "谢谢使用~";
            } else {
                message = "再来一次~";
            }
            System.out.println(message);
        }
        sc.close();
    }
}